package com.mvity.framework.system.web.controller;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mvity.framework.common.annotation.ControllerDesc;
import com.mvity.framework.common.base.BaseController;
import com.mvity.framework.common.global.ExtJSGridResponse;
import com.mvity.framework.common.global.ExtJSResponse;
import com.mvity.framework.common.global.IResponseOutput;
import com.mvity.framework.system.entity.SystemComponent;
import com.mvity.framework.system.service.ComponentService;
import com.mvity.framework.system.vo.ComponentVO;

@Controller
@RequestMapping(value = "/component")
public class ComponentController extends BaseController {

	@Resource
	private ComponentService componentService;
	
	private static final long serialVersionUID = -2071521307572018039L;

	@ControllerDesc("保存组件")
	@RequestMapping(value = "/save")
	@ResponseBody
	public IResponseOutput save(HttpServletRequest request, SystemComponent component) {
		component.setOperator(this.getCurrentSessionUser(request));
		componentService.save(component);
		System.out.println(component.toString());
		return ExtJSResponse.successResponse;
	}

	@ControllerDesc("加载组件列表")
	@RequestMapping(value = "/list")
	@ResponseBody
	public IResponseOutput list(@RequestParam int limit) {
		List<ComponentVO> list = new ArrayList<ComponentVO>();
		for (int i = 0; i < limit; i++) {
			ComponentVO vo = ComponentVO.fromEntity(ComponentVO.class, new SystemComponent());
			vo.setId(System.currentTimeMillis() + "");
			list.add(vo);

		}
		return new ExtJSGridResponse<ComponentVO>(50, list);
	}
}
